package com.veer.shop.controller.admin;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.veer.shop.annotation.ApiControllerLog;
import com.veer.shop.annotation.ApiSecured;
import com.veer.shop.config.ApiUrlConfig;
import com.veer.shop.pojo.User;
import com.veer.shop.pojo.AdminLogin;
import com.veer.shop.pojo.ResponseData;
import com.veer.shop.service.impl.admin.AdminUserServiceImpl;
import com.veer.shop.service.impl.admin.AuthorizeServiceImpl;

/**
 * 管理员用户管理 控制器
 * 
 * @author WangBin
 * 2020年8月15日-下午2:47:20
 */
@RestController
public class UserController {
	
	@Autowired
	private AdminUserServiceImpl adminUserServiceImpl;
	@Autowired
	private AuthorizeServiceImpl authorizeServiceImpl;
	
	/**
	 * 新增/更新管理员
	 */
	@ApiSecured
	@RequestMapping( path = ApiUrlConfig.API_ADMIN_USER_CREATE_URL, method = RequestMethod.POST)
	public ResponseData<?> updateAdminUser(@RequestBody User adminUserEntity)
	{
		return adminUserServiceImpl.update(adminUserEntity);
	}
	
	/**
	 * 查询管理员列表
	 * 
	 * @param filters
	 * @return
	 */
	@ApiSecured
	@RequestMapping( path = ApiUrlConfig.API_ADMIN_USER_LIST_URL, method = RequestMethod.POST)
	public ResponseData<?> getAdminUserList(@RequestBody(required=false) Map<String, String> filters)
	{
		return adminUserServiceImpl.getList(filters);
	}
	
	/**
	 * 获取管理员Token
	 */
	@ApiControllerLog(description = "获取管理员Token")
	@RequestMapping(path = ApiUrlConfig.API_ADMIN_TOKEN_URL, method = RequestMethod.POST)
	public ResponseData<?> getAdminToken(@RequestBody AdminLogin param)
	{
		return authorizeServiceImpl.getAdminToken(param.getUsername(), param.getPassword());
	}
}
